package com.ruoyi.web.controller.business;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.ruoyi.business.pojo.dto.*;
import com.ruoyi.ruoyi.business.pojo.vo.MaterialDetailVo;
import com.ruoyi.ruoyi.business.pojo.vo.MaterialListClassifyVo;
import com.ruoyi.ruoyi.business.pojo.vo.MaterialListVo;
import com.ruoyi.ruoyi.business.service.smo.MaterialService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName：TutorialController
 * Package：com.ruoyi.web.controller.business
 * Description：教程资料
 *
 * @Author：fpy
 * @Create：2025/5/8 - 14:34
 * @Version：v1.0
 */
@RestController
@RequestMapping("/material")
public class MaterialController extends BaseController {
    @Resource
    private MaterialService materialService;

    /**
     * 教程列表
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult<com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.ruoyi.ruoyi.business.pojo.vo.MaterialListVo>>
     * @author: fpy
     * @date: 2025/5/8 14:41
    **/
    @PostMapping("/list")
    @PreAuthorize("@ss.hasPermi('business:material:list')")
    public AjaxResult<Page<MaterialListVo>> list(@RequestBody @Validated MaterialListDto dto) {
        return materialService.list(startPage(), dto);
    }

    /**
     * 新增教程
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult
     * @author: fpy
     * @date: 2025/5/8 14:44
    **/
    @PostMapping("/add")
    @PreAuthorize("@ss.hasPermi('business:material:add')")
    public AjaxResult add(@RequestBody @Validated MaterialAddDto dto) {
        return materialService.add(dto);
    }

    /**
     * 删除教程
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult
     * @author: fpy
     * @date: 2025/5/8 15:01
    **/
    @PostMapping("/remove")
    @PreAuthorize("@ss.hasPermi('business:material:remove')")
    public AjaxResult remove(@RequestBody @Validated MaterialRemoveDto dto) {
        return materialService.remove(dto);
    }

    /**
     * 教程详情
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult<com.ruoyi.ruoyi.business.pojo.vo.MaterialDetailVo>
     * @author: fpy
     * @date: 2025/5/8 15:03
    **/
    @PostMapping("/detail")
    @PreAuthorize("@ss.hasPermi('business:material:list')")
    public AjaxResult<MaterialDetailVo> detail(@RequestBody @Validated MaterialDetailDto dto) {
        return materialService.detail(dto);
    }

    /**
     * 修改教程
     *
     * @param: dto
     * @return: com.ruoyi.common.core.domain.AjaxResult
     * @author: fpy
     * @date: 2025/5/8 15:09
    **/
    @PostMapping("/edit")
    @PreAuthorize("@ss.hasPermi('business:material:edit')")
    public AjaxResult edit(@RequestBody @Validated MaterialEditDto dto) {
        return materialService.edit(dto);
    }

    /**
     * 查询分类列表
     *
     * @param:
     * @return: com.ruoyi.common.core.domain.AjaxResult<MaterialListClassifyVo>
     * @author: fpy
     * @date: 2025/5/8 15:14
    **/
    @PostMapping("/list/classify")
    @PreAuthorize("@ss.hasPermi('business:material:list')")
    public AjaxResult<List<MaterialListClassifyVo>> listClassify() {
        return materialService.listClassify();
    }

}
